package com.elitel.frame.base.controller;

import com.elitel.frame.base.service.PageBaseInfoService;
import com.elitel.frame.base.service.SysPrjServiceService;
import com.elitel.frame.main.entity.PageBaseinfo;
import com.elitel.frame.main.entity.ext.PageBaseinfoExt;
import com.elitel.frame.main.entity.vo.JsonResult;
import com.elitel.frame.main.entity.vo.PageRequestVo;
import com.elitel.frame.main.entity.vo.PageResponseVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/system/sysPageBaseInfo")
public class PageBaseInfoController {
    private static final Logger logger = LoggerFactory.getLogger(SysPrjServiceController.class);

    @Autowired
    private SysPrjServiceService sysPrjServiceService;
    @Autowired
    private PageBaseInfoService pageBaseInfoService;

    /**
     * TODO: 获取基本信息配置列表
     * @param pageNo
     * @param pageSize
     * @param seachTxt
     * @param pcode
     * @param servertype
     * @return
     */
    @RequestMapping("/getPageBaseInfoList")
    @ResponseBody
    public Object getPageBaseInfoList(String pageNo, String pageSize, String seachTxt, String pcode,
                                      String servertype) {
        JsonResult jr = new JsonResult();
        try {
            PageRequestVo<PageBaseinfoExt> pr = new PageRequestVo<PageBaseinfoExt>();
            pr.setSearchContent(seachTxt);
            pr.setPageNo(Integer.valueOf(pageNo));
            pr.setPageSize(Integer.valueOf(pageSize));
            pr.setTreeCode(pcode);
            pr.setContentType(servertype);
            PageResponseVo<PageBaseinfoExt> pagelist = pageBaseInfoService.getPageBaseInfoList(pr);
            jr.setData(pagelist);
            jr.setSuccess(true);
        } catch (Exception e) {
            jr.setSuccess(false);
            jr.setMsg("工程服务信息加载异常！");
            logger.error(e.getMessage(), e);
        }
        return jr;
    }

    /**
     * TODO: 获取页面基本信息
     * @param pagecode
     * @return
     */
    @RequestMapping("/getPageBaseInfoByPageCode")
    @ResponseBody
    public Object getPageBaseInfoByPageCode(String pagecode) {
        JsonResult jr = new JsonResult();
        try {
            PageBaseinfo pageBaseinfo = new PageBaseinfo();
            pageBaseinfo = pageBaseInfoService.getPageBaseInfoByPageCode(pagecode);
            jr.setSuccess(true);
            jr.setData(pageBaseinfo);
        } catch (Exception e) {
            jr.setSuccess(false);
            jr.setMsg("获取信息异常！");
            logger.error(e.getMessage(), e);
        }
        return jr;
    }

    /**
     * TODO: 添加页面基本信息配置
     * @param pageBaseinfo
     * @return
     */
    @RequestMapping("/insertPageBaseInfo")
    @ResponseBody
    public Integer insertPageBaseInfo(PageBaseinfo pageBaseinfo) {
        Integer result = 0;
        try {
            result = pageBaseInfoService.insertSelective(pageBaseinfo);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }
    /**
     * TODO: 删除页面基本信息
     * @param pagecode
     * @return
     */
    @RequestMapping("/deletePageBaseInfo")
    @ResponseBody
    public Integer deletePageBaseInfo(String pagecode) {
        Integer result = 0;
        try {
            result = pageBaseInfoService.deleteByPrimaryKey(pagecode);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }

    /**
     * TODO: 更改页面基本信息配置
     * @param pageBaseinfo
     * @return
     */
    @RequestMapping("updatePageBaseInfo")
    @ResponseBody
    public Integer updatePageBaseInfo(PageBaseinfo pageBaseinfo) {
        Integer result = 0;
        try {
            result = pageBaseInfoService.updateByPageCode(pageBaseinfo);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }
}
